package cs235.xml;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;

public class XMLDocument extends XMLNode implements Document {

    public XMLDocument() {
        super(DOCUMENT_NODE, null);
    }

    @Override
    public void write(OutputStream output) throws IOException {
        OutputStreamWriter writer = new OutputStreamWriter(output);
        writer.write(toString());
        writer.flush();
    }
    
    @Override
    public String toString(){
        StringWriter writer = new StringWriter();
        Node child = getFirstChild();
        while (child!=null){
            writer.write(child.toString());
            child = child.getNextSibling();
        }
        return writer.toString();
        
    }

}
